/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package east2west.action;

import east2west.dao.FlightDAO;
import east2west.dto.TourDTO;
import east2west.service.TourService;
import east2west.dto.CarModelDTO;
import east2west.dto.CarTypesDTO;
import east2west.dto.CarsDTO;
import east2west.dto.FlightsDTO;
import east2west.dto.HotelDTO;
import east2west.dto.LocationDTO;
import east2west.dto.TourTypeDTO;
import east2west.service.CarModelService;
import east2west.service.CarService;
import east2west.service.CarTypeService;
import east2west.service.FlightsService;
import east2west.service.HotelService;
import east2west.service.LocationService;

import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author thanhluan
 */
public class HomeAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
//Manager Tour (show tour in index)
//----------------------------------------------------------------------------------------------
        TourService serTour = new TourService();
        FlightsService flightSer = new FlightsService();
        CarService serCar = new CarService();
        LocationService locationser = new LocationService();

        //-----------------------------------------------

        ArrayList<TourDTO> listTop = new ArrayList<TourDTO>();
        listTop = serTour.readByTopTour();
        request.setAttribute("listTopTour", listTop);
        //---------------------------------------------------------------------------------------------------
        ArrayList<TourDTO> listShowTop = new ArrayList<TourDTO>();
        listShowTop = serTour.findByShowTourTop();
        request.setAttribute("listShowTour", listShowTop);
        //---------------------------------------------------------------
        ArrayList<TourDTO> list = new ArrayList<TourDTO>();
        list = serTour.readByAll();
        request.setAttribute("list", list);
        //--------------------------------------------------------------------
        //Manager Flight(show flight)
        FlightDAO dao = new FlightDAO();
        ArrayList<FlightsDTO> listFlight = dao.findByTop();
        request.setAttribute("listFlight", listFlight);



//-------------------------------------------------------------------------------------------------
//list of car top 10

        ArrayList<CarsDTO> listCar = serCar.readByTopCar(10);
        request.setAttribute("listCar", listCar);

//-----------------------------------------------------------------------------------------------

//otel top 10

        HotelService hotelSer = new HotelService();
        ArrayList<HotelDTO> listhotel = new ArrayList<HotelDTO>();
        listhotel = hotelSer.readByTopHotel();
        request.setAttribute("listHotel", listhotel);


        //------------------------------------------------------------------------------------------------
        //Search
        HttpSession session = request.getSession(true);
        ArrayList<TourDTO> listDeparture = serTour.readByAllDeparture();
        session.setAttribute("listDeparture", listDeparture);

        ArrayList<TourDTO> listDestination = serTour.readByAllDestination();
        session.setAttribute("listDestination", listDestination);

        ArrayList<TourTypeDTO> listAllTourType = serTour.readByTourType();
        session.setAttribute("listTourType", listAllTourType);

        ArrayList<LocationDTO> listLocation = locationser.readBySAll();
        session.setAttribute("listLocation", listLocation);



//endsearch
        //start search flight
        ArrayList<FlightsDTO> listDepartureS = flightSer.getFlightDeparture();
        ArrayList<FlightsDTO> listDestinationS = flightSer.getFlightDestination();
        session.setAttribute("listDepartureS", listDepartureS);
        session.setAttribute("listDestinationS", listDestinationS);

        //end search flight
        //start hotel search
        ArrayList<HotelDTO> listCity = hotelSer.getCity();
        session.setAttribute("listCity", listCity);
        //end search hotel
        //list of car type
        ArrayList<CarTypesDTO> listType = new ArrayList<CarTypesDTO>();
        CarTypeService carTypeSer = new CarTypeService();
        listType = carTypeSer.readByAll();
        request.setAttribute("listType", listType);

        //list of car model
        ArrayList<CarModelDTO> listModel = new ArrayList<CarModelDTO>();
        CarModelService carModelSer = new CarModelService();
        listModel = carModelSer.readByAll();
        request.setAttribute("listModel", listModel);

        return mapping.findForward(SUCCESS);

    }
}
